<template>
  <!-- 登录的页面 -->
  <div class="login_container">
    <!-- 登录的form表单 -->
    <div class="login_box">
      <!-- 头像 -->
      <div class="avatar_box">
        <img src="../../assets/imgs/duanwu.png" alt="" />
      </div>
      <!-- 登录的表单组件 -->
      <el-form
        :model="loginForm"
        :rules="rules"
        ref="loginForm"
        label-width="0px"
        class="login_form"
      >
        <el-form-item prop="username">
          <el-input
            v-model="loginForm.username"
            placeholder="请输入用户名称"
            prefix-icon="el-icon-user-solid"
          ></el-input>
        </el-form-item>
        <el-form-item prop="password">
          <el-input
            v-model="loginForm.password"
            placeholder="请输入登录密码"
            prefix-icon="el-icon-lock"
          ></el-input>
        </el-form-item>
        <el-form-item prop="verifyCode">
          <div class="verifyCode_box">
            <el-input
              v-model="loginForm.verifyCode"
              placeholder="请输入手机验证码"
              prefix-icon="el-icon-mobile"
              class="verifyCode"
            ></el-input>
            <img
              src="../../assets/imgs/yzm.png"
              alt=""
              class="verifyCode_img"
            />
          </div>
        </el-form-item>
        <el-form-item class="login_btn">
          <el-button type="primary" @click="submitForm('loginForm')"
            >立即创建</el-button
          >
          <el-button @click="resetForm('loginForm')">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      loginForm: {
        username: "kjh",
        password: "123456",
      },
      rules: {
        username: [
          { required: true, message: "用户名称不能为空", trigger: "blur" },
        ],
        password: [
          { required: true, message: "登录密码不能为空", trigger: "blur" },
        ],
        verifyCode: [
          { required: true, message: "请填写验证码", trigger: "blur" },
        ],
      },
    };
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$router.push("/home");
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
  },
};
</script>

<style lang="less" scoped>
.login_container {
  height: 100%;
  background-color: aquamarine;
  display: flex;
  // 上下居中
  align-items: center;
  //   左右居中
  justify-content: center;

  .login_box {
    width: 450px;
    height: 320px;
    background-color: #ffffff;
    border-radius: 3px;
    padding: 100px 20px 0px 20px;
    position: relative;

    .avatar_box {
      width: 130px;
      height: 130px;
      position: absolute;
      left: 165px;
      top: -85px;
      border: 1px solid #cccccc;
      padding: 10px;
      border-radius: 50%;
      background-color: #fff;
      img {
        width: 100%;
        height: 100%;
        border-radius: 50%;
      }
    }

    .verifyCode_box {
      display: flex;

      .verifyCode {
        flex: 2;
      }

      image {
        flex: 1;
      }
    }
  }
}
</style>
